var customers;

$('#accountListPage').bind('pageinit', function(event) {
	getCustomerList('smith');
});

function getCustomerList(userId) {
	$.getJSON(serviceURL + "accounts/" + userId, function(data) {
		$('#accountList li').remove();
		customers = data;
		$.each(customers, function(idx, customer) {
			$('#accountList').append('<li data-role="list-divider">'+customer.label+'</li>');
			$.each(customer.accounts, function(idx2, account) {
				$('#accountList').append('<li><a href="operations.html?accountId=' + account.id + '">'+account.label+'<br/>'+account.balance+' &euro;</a></li>');
			});
		});
		$('#accountList').listview('refresh');
	});
}
